﻿#region Copyright 2008 - Evolution Systems.
//
// Author: José Rogério Ferreira dos Santos(joserogerio.santos@gmail.com)
// Date: 18/01/2009
// Time: 20:33
// All rights are reserved. Reproduction or transmission in whole or in part, in
// any form or by any means, eletronic, mechanical or otherwise, is prohibited
// without the prior written permission of the author.
//
// Filename: ${FILE_NAME}.cs
#endregion
using System;
using System.Collections.Generic;

namespace csharp.rad.general
{
	/// <summary>
	/// Description of Company.
	/// </summary>
	public class Company : csharp.common.DefaultClass, csharp.common.IClass
	{
		public Person person = new Person();
		
		public Company()
		{
			clear();
			gsql.table		= "common.company";
			_sequence		= "common.company_company_id_seq";
		}
		
		public void clear()
		{
			_id   = String.Empty;
			person.clear();
		}
		
		public override void get(System.Data.DataRow dr)
		{
			_id		 = dr["company_id"].ToString();
			person.id = dr["company_person_id"].ToString();
			person.get();
		}
		
		public override void setGsql()
		{
			gsql.setValue(_id, "company_id");
			gsql.setValue(person.id, "company_person_id");
		}
		
	}
	
	public class Companies : csharp.common.DefaultList, csharp.common.IList
	{
		public Companies()
		{
			gsql.table = "common.company";
		}
				
		public Company get()
		{
			return (Company)items[index];
		}
		
		public Company get(int index)
		{
			return (Company)items[index];
		}
		
		public bool fillList()
		{
			gsql.prepare();
			gsql.setValue("","*");
			
			return mountList();
		}
		
		private bool mountList()
		{
			if (!gsql.execute())
			{
				msgErro= gsql.getMsgErro();
				return false;
			}
			items.Clear();
			int tam = gsql.getRowCount();
			for(int i=0; i < tam; i++)
			{
				Company c = new Company();
				c.get(gsql.getRow(i));
				
				items.Add(c);
			}
			return true;
		}
	}	
}
